home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.686 < prev    next >
Text File  |  1992-02-06  |  3KB  |  86 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f3\fmodern Courier;\f1\fswiss Helvetica;}
  2. \paperw11440
  3. \paperh8340
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 TIFF files reading writing compression\
  8.     \
  9.  
  10. \fi-400\li400 Q:  I am writing an app where I read and write TIFF files.  When I open a TIFF file I would like to know what kind of compression may have been used on that image so I can save it out with the same format.  How can I do this?\
  11.  
  12. \i\fi0\li0     \
  13.  
  14. \i0\fi-400\li400 A:  There is no NXBitmapImageRep method that will allow you to do this.  However there is a 1.0 routine (still supported in 2.0) called 
  15. \f3\fs24 NXGetTIFFInfo()
  16. \f0\fs28  which will return information about a TIFF file.  In general, we do not recommend that you use 
  17. \f3\fs24 NXGetTIFFInfo()
  18. \f0\fs28  for anything other than looking at compression information or how many images a TIFF file may contain.  The NXBitmapImageRep class in 2.0 is the recommended manner for managing TIFF files.\
  19. \
  20.  
  21. \fi0 Here is a code sample which uses NXGetTIFFInfo to examine the file 'fileName' (probably returned from the OpenPanel).  Also a couple things to note:\
  22. \
  23.  
  24. \fi-180\li580\fc0 • The count returned represents the number of bytes when the image is uncompressed.  There is no way to determine how many compressed bytes the image consumes.  \
  25. \
  26. • In this example the imageNumber has been hardcoded to zero.  It is possible to store more than one image in a TIFF file.  After you've received the NXTIFFInfo structure for the first image you can look at the info.numImages field to see if there are other images there that you may wish to peruse.  For example some application icons have two images in the same TIFF file -- one 2-bit image for B&W monitors, one 16-bit image for color monitors.  The appkit extracts the appropriate image.\
  27. \
  28. • There is no way to determine which compression factor was used for a JPEG image.\
  29.  
  30. \fi0\li400 \
  31. \
  32.  
  33. \pard\tx620\tx1240\tx1860\tx2480\tx3100\tx3720\tx4340\tx4980\tx5600\tx6220\f3\fs24\fc0 #import <streams/stream.h>\
  34. #import <appkit/tiff.h>\
  35. \
  36. \
  37.     NXStream *stream;\
  38.     NXTIFFInfo info;\
  39.     int count;\
  40. \
  41.     if (!(stream = NXMapFile(fileName, NX_READONLY)))\
  42.     \{\
  43.         perror(fileName);\
  44.     \}\
  45.     else\
  46.     \{\
  47.         if (!(count = NXGetTIFFInfo(0, stream, &info)))\
  48.         \{\
  49.             /* it didn't work -- see tiff.h for list of errors */\
  50.             printf("error #%d\\n", info.error);\
  51.         \}\
  52.         else\
  53.         \{\
  54.             printf("%s:  %d bytes, ", fileName, count);\
  55.             /* see tiff.h for complete list of compression schemes */\
  56.             switch(info.compression)\
  57.             \{\
  58.             case NX_TIFF_COMPRESSION_NONE:\
  59.                 printf("no compression\\n");\
  60.                 break;\
  61.             case NX_TIFF_COMPRESSION_LZW:\
  62.                 printf("LZW compression\\n");\
  63.                 break;\
  64.             case NX_TIFF_COMPRESSION_JPEG:\
  65.                 printf("JPEG compression\\n");\
  66.                 break;\
  67.             \}\
  68.         \}\
  69.         NXCloseMemory(stream, NX_FREEBUFFER);\
  70.     \}\
  71.  
  72. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600 \
  73. \
  74.  
  75. \f0\fs28\fi-1200\li1200 See also:  The 
  76. \b tiffutil
  77. \b0  command-line utility in 2.0 also provides a quick way to extract information about a TIFF file in a Terminal window.  There is a man page on tiffutil.\
  78.  
  79. \fi0\li0 \
  80. QA686\
  81. \
  82. Valid for 1.0, with exceptions noted.\
  83. Valid for 2.0                \
  84. \
  85.  
  86.